
int count;

main()
{
  while (1)
  {
    loop();
    delay(1);
  }
}


loop()
{
  startThread("makeOnChangeSubsystem");
}

void makeOnChangeSubsystem()
{

  string sql;

  sql = "SELECT '_original.._value' FROM '*.STATE.*.VALUE' "
        "WHERE _LEAF " ;


  dyn_dyn_anytype ddaTab;

  dpQuery(sql, ddaTab);

  int iLen = dynlen(ddaTab);
  int subsyscont;

  for (int i = 2; i <= iLen; i++)
  {

    if (count == 200)
    {
      count = 0;
      delay(0, 2);
    }

    string dpe = ddaTab[i][1];

    if (strpos(dpe, "HOUR.VALUE") > 0) continue;

    if (strpos(dpe, "MINUTE.VALUE") > 0) continue;


    if (dpElementType(dpe) == DPEL_FLOAT)
    {

      float value;
      string sUnit =  dpGetUnit(dpe);

      if (sUnit == "℃")
      {
        value = 22.5 + (float)rand() / 32767.0 ;
        string sValue;

        sprintf(sValue, "%4.2f", value);
        dpSet(dpe, (float)sValue);

        count++;
        // delay(0, 1);
      }
      else
      {
        value = 1.5 + (float)rand() / 32767.0 ;
        string sValue;

        sprintf(sValue, "%4.2f", value);
        dpSet(dpe, (float)sValue);
        count++;
      }

      subsyscont++;

    }
  }

  // DebugTN(sysName + " simulation dp count:" + subsyscont + " TOTAL:" + iLen);
}

